package com.example.test;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class MyBroadcastReceiver extends BroadcastReceiver {

    public static final String STANDARD_ACTION = "android.provider.Telephony.SMS_RECEIVED";
    @Override
    public void onReceive(Context context, Intent intent) {
//        如果属于该广播要接受的消息，就执行
        if(intent.getAction() != null && intent.getAction().equals(STANDARD_ACTION)) {
//            启动音乐播放服务
            startMusicService(context);
        }
    }

    private void startMusicService(Context context) {
        Intent intent = new Intent(context, MyService1.class);
        context.startService(intent);
    }
}
